
import 'package:flutter/cupertino.dart';

class MyNavigatorObservers extends NavigatorObserver{
  // 调用Navigator.push 时回调
  @override
  void didPush(Route route, Route previousRoute) {
    // TODO: implement didPush
    super.didPush(route, previousRoute);
    // 获取路由名称
    print("didPush settings is" + route.settings.toString());
    print("didPush settings.name is" + route.settings.name.toString());
    // 获取上一个页面的信息
    if(previousRoute != null){
      print("didPush previousRoute settings is" + previousRoute.settings.toString());
      print("didPush previousRoute.name settings is" + previousRoute.settings.name.toString());

    }
  }

  // 当调用Navigator.pop时回调
   @override
  void didPop(Route route, Route previousRoute) {
    // TODO: implement didPop
    super.didPop(route, previousRoute);
    // 获取路由名称
    print("didPop settings is" + route.settings.toString());
    print("didPop settings.name is" + route.settings.name.toString());
    // 获取上一个页面的信息
    if(previousRoute != null){
      print("didPop previousRoute settings is" + previousRoute.settings.toString());
      print("didPop previousRoute.name settings is" + previousRoute.settings.name.toString());

    }

  }
}